
Page({

  /**
   * 页面的初始数据
   */
  data: {
    schema:[
      {
        label:'图片地址',
        prop:'url',
        type:'text'
      }
    ],
    formData:{
      url: 'https://product.lvcampaign.com/attached/107/images/2025-08-19/804fa5dd3f2544158904759b61d491b1.png'
    },
    title: '',
    result: '',
    remark: '',
    webUrl: '',
    apiName: ''
  },
  onLoad(options) {
    console.log('options', options)
    wx.setNavigationBarTitle({
      title: options.title,
    })
    
    this.setData({
      title: options.title,
      zh:options.zh,
      remark: options.remark,
      webUrl: options.webUrl
    })
  },
  getFormData(e) {
    this.setData({
      formData: e.detail.formData
    })
  },
  choose1(e) {
    const that = this;
    wx.downloadFile({
      url: this.data.formData.url,
      success(res) {
        console.log(res);
        if(res.statusCode === 200) {
          const tempFilePath = res.tempFilePath
          wx.showModal({
            title: '获取临时文件路径成功,点击确定保存到系统相册',
            content: tempFilePath,
            showCancel: false,
            complete: (res) => {
              if (res.confirm) {
                wx.saveImageToPhotosAlbum({
                  filePath: tempFilePath,
                  success (res) {
                    that.setData({
                      result: res,
                      apiName: e.currentTarget.dataset.apiname
                    })
                  },
                  fail(err) {
                    that.setData({
                      result: err,
                      apiName: e.currentTarget.dataset.apiname
                    })
                  }
                })
              }
            }
          })
        } else {
          wx.showModal({
            title: '下载图片失败，获取临时文件路径失败',
            content: res,
            showCancel: false
          })
        }
      },
      fail(err) {
        wx.showModal({
          title: '下载图片失败，获取临时文件路径失败',
          content: err,
          showCancel: false
        })
      }
    })
  },
  onUnload() {
  }
})